#
# @lc app=leetcode.cn id=46 lang=python3
#
# [46] 全排列
#

# @lc code=start
class Solution:

    def permute(self, nums: List[int]) -> List[List[int]]:
        res = []
        track = []

        def backtrack(nums, track):
            # 触发结束条件
            if len(track) == len(nums):
                res.append(track[:])

            for num in nums:
                # 排除不合法的选择
                if num in track:
                    continue
                # 做选择
                track.append(num)
                # 进入下一层决策树
                backtrack(nums, track)
                # 取消选择
                track.pop()

        backtrack(nums, track)

        return res
# @lc code=end
